package pack0820;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

//时间
public class DemoB {
    public static void a(){
        //获取当前系统时间
        Date date = new Date();
        int year = date.getYear()+1900;
        int month = date.getMonth()+1;
        int date1 = date.getDate();
        int hour = date.getHours();
        int mainute = date.getMinutes();
        int second = date.getSeconds();
        //1970年1月1日0点0分0秒到现在的毫秒值
        long time = date.getTime();
        System.out.println(year);
        System.out.println(month);
        System.out.println(date1);
        System.out.println(hour);
        System.out.println(mainute);
        System.out.println(second);
        System.out.println(time);
    }

    public static void b(){
        Date date = new Date();
        System.out.println(date);
        /*yyyy 年
        MM 月
        dd 日
        hh/HH 12小时/24小时
        mm
        ss 秒
        W 星期
        */
        SimpleDateFormat str = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss 星期：W ");
        String strFormat = str.format(date);
        System.out.println(strFormat);
    }

    public static void c(){
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar);
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int date = calendar. get(Calendar.DATE);
        int hour = calendar.get(Calendar.HOUR);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
        System.out.println(year);
        System.out.println(month+1);
        System.out.println(date);
        System.out.println(hour);
        System.out.println(minute);
        System.out.println(second);
    }

    public static void main(String[] args) {
        c();
    }
}
